home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / wided.pro < prev    next >
Text File  |  1997-07-08  |  12KB  |  394 lines

  1. ;
  2. ; $Id: wided.pro,v 1.19 1997/01/20 17:56:35 beth Exp $
  3. ;
  4. ;
  5. ;  WidEd
  6. ;   Entry point for widget builder.
  7. ;   Reads in all related functions and procedures.
  8. ;
  9. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  10. ;   Unauthorized reproduction prohibited.
  11. ;
  12. ; Version   = Beta 0.9
  13. ;
  14. ;+
  15. ; NAME:
  16. ;       WIDED
  17. ;
  18. ; PURPOSE:
  19. ;       An IDL dialog Editor.  Lets one graphically produce a widget
  20. ;       hierarchy.
  21. ;
  22. ; CATEGORY:
  23. ;       Widgets.
  24. ;
  25. ; CALLING SEQUENCE:
  26. ;       WIDED [, File ]
  27. ;
  28. ; OPTIONAL INPUTS:
  29. ;       File:   Widget builder will read this file.  File should
  30. ;               be a widget file (.WID)
  31. ;
  32. ; KEYWORD PARAMETERS:
  33. ;       None.
  34. ;
  35. ; COMMON BLOCKS:
  36. ;
  37. ;       FMagic_Comm     -- Store global variable, NoCheck.
  38. ;       TestDraw_Comm   -- Saves a seed number used in random plot generation
  39. ;       WidDirty_Comm   -- Save Yes/No/Cancel information in Dirty
  40. ;       WidEd_Comm      -- Global variables used through the Widget Builder
  41. ;                       Definition of this common block in in wided.com
  42. ;       XPrintf_Comm    -- Save I/O state to allow multiple I/O operations
  43. ;                       to write a single line.  FORMAT=(..., $) doesn't
  44. ;                       work on VMS and this needs to work *EVERYWHERE*
  45. ;
  46. ; SIDE EFFECTS:
  47. ;       Builds widget trees.  Writes IDL Code.  Probably more side
  48. ;       effects than you can shake a stick at.
  49. ;
  50. ; RESTRICTIONS:
  51. ;       You must have IDL 3.5 or later.  This is a graphical program
  52. ;       so widgets must be available.
  53. ;
  54. ; PROCEDURE:
  55. ;       Add, delete, cut, copy and paste widgets to your hearts delight.
  56. ;       Save the results if you want to.
  57. ;
  58. ; EXAMPLE:
  59. ;       Please see the "Using the IDL Widget Builder" document.
  60. ;
  61. ; MODIFICATION HISTORY:
  62. ;       Written by:     Joshua Goldstein,       Spring '93
  63. ;
  64. ;       Fall '93        Complete rewrite using widget UVALUEs instead
  65. ;                       of uniform structures to store hierarchy. Added
  66. ;                       bitmapped buttons, pull down menus, embedded
  67. ;                       comments in .PRO files to save user mods.
  68. ;                       Made adding user classes even easier (add 1 line
  69. ;                       to widdef.dat).  Still need to write class library.
  70. ;                       Added comments to wided.  Hope they help.
  71. ;
  72. ;-
  73.  
  74. ;
  75.  
  76.  
  77. pro wided_common
  78.    ; The only  purpose of this routine is that it should be
  79.    ; the first thing compiled in the widget builder. It defines
  80.    ; WidEd_Comm COMMON block, and allows the other routines to
  81.    ; simply ask for the block name without providing the variable names.
  82.  
  83.   COMMON WidEd_Comm,  $
  84.     Bases,          $       ; Top level bases in preview
  85.     BaseXY,            $        ; Remember if user moves bases
  86.     Dirty,          $       ; TRUE if object tree has been modified
  87.     InDestroy,      $       ; TRUE during parts of destroy processing.
  88.     FileName,       $       ; Current file name
  89.     FileDir,        $       ; Current directory
  90.     NewDialogs,     $       ; Active Dialog information
  91.     TopPtr,         $       ; MAIN Object. Root of object tree
  92.     TopDlg,         $       ; Main dialog box id. Group leader to all
  93.     CutList,        $       ; List of last 10 objects cut
  94.     LastId,         $       ; Last Id used so far.
  95.     AddList,        $       ; class list
  96.     CutId, CopyId,  $       ; Ids for the 4 dialog boxes which need to be
  97.     PasteId, EditId, $      ; updated whenever an object is added/delete
  98.     OnAPC,        $        ; PC's have no visible text border
  99.     SmallScreen            ; MAC's (maybe others) need scrolling bases
  100.  
  101. end
  102.  
  103.  
  104.  
  105.  
  106. ;
  107. ;   We need to predeclare some functions so that things compile properly
  108. ;
  109.  
  110. FUNCTION NextPtr, Ptr & RETURN,0L & END
  111. FUNCTION VarName, Ptr & RETURN,'' & END
  112.  
  113. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  114.  
  115.  
  116. ;
  117. ;  Init
  118. ;   Initialize global variables.  Destroy the old object tree (if it
  119. ;   exists).  Create a new object tree with only one object: the MAIN base.
  120. ;
  121. PRO Init, COMPILE_ONLY=NoRealize
  122.  
  123.   COMMON WidEd_Comm
  124.  
  125.     COMMON  XPrintf_Comm, OutputBuffer, ArgList
  126.  
  127.     ;   Support and library routines.
  128.  
  129.     WidUtil
  130.     WidAlloc
  131.     WidBuild
  132.     WidEdit
  133.     WidFile
  134.     WidMain
  135.     WidDep
  136.  
  137.  
  138.     ;  PC's need frames on their text fields.
  139.  
  140.     OnAPC =  (!Version.OS EQ 'Win32')
  141.  
  142.  
  143.     IF N_ELEMENTS(TopPtr) EQ 0 THEN TopPtr = 0L
  144.     TopDlg      = 0L
  145.  
  146.     ;   Destroy the old object tree.
  147.  
  148.     IF WIDGET_INFO(TopPtr, /VALID) THEN BEGIN
  149.  
  150.         ;   We can get into a state where TopPtr is valid but
  151.         ;   does not contain anything. So we check everything
  152.  
  153.         IF WIDGET_INFO(TopPtr, /VALID_ID) THEN BEGIN    ; is TopPtr valid
  154.             Ptr2Obj, TopPtr, Obj
  155.             IF KEYWORD_SET(Obj) THEN BEGIN  ; Does it contain an obj?
  156.                 Obj2Ptr, Obj, TopPtr        ; Put obj back into pointer
  157.                 Destroy, TopPtr             ; Destroy it
  158.             ENDIF
  159.         ENDIF
  160.     ENDIF ELSE BEGIN
  161.         TopPtr  = 0L
  162.     ENDELSE
  163.  
  164.     Bases       = LONARR(100)       ; #define MAXTOP 100
  165.     BaseXY      = INTARR(2,100)     ; BaseXY[MAXTOP][2]
  166.     Dirty       = 0                 ; no changes yet
  167.     InDestroy   = 0                 ; not destroying anything right now
  168.     FileName    = "unknown"         ; no current file
  169.     FileDir     = ""                ; no current directory
  170.  
  171.     ;   declare the different structure types used
  172.  
  173.     Dummy       = { CW_PDMENU_S, flags:0, name:'' }
  174.     Dummy       = { WE_MENUITEM, Str: '', SubMenuPtr: 0L }
  175.     NewDialogs  = { WE_NEWOBJ, ParPtr:0L, ObjPtr:0L, OldPtr:0L }
  176.     AddList     = { WE_ADDLIST, Menu:'', Class: '' }
  177.  
  178.     CutId       = 0     ; No Cut Dialog
  179.     CopyId      = 0     ; No Copy Dialog
  180.     EditId      = 0     ; No Edit Child dialog
  181.     PasteId     = 0     ; No Paste Dialog
  182.  
  183.     LastId      = 1 ; No widgets created yet.
  184.  
  185.     ;   Assume that there are valid items on the cutlist if it exists
  186.     ;   otherwise make it the nil list.
  187.     IF N_ELEMENTS(CutList) EQ 0 THEN CutList = 0L $
  188.     ELSE IF WIDGET_INFO(CutList, /VALID) EQ 0 THEN CutList = 0L
  189.  
  190.     ;   Open the definition file
  191.     GET_LUN, Unit
  192.     DefFile     = "widdef.dat"
  193.     OPENR, Unit, DefFile, ERROR = OpenError
  194.     IF OpenError NE 0 THEN BEGIN
  195.         DefFile = FilePath("widdef.dat", SUBDIR=["lib", "obsolete"])
  196.         OPENR, Unit, DefFile
  197.     ENDIF
  198.  
  199.     Line    = ''
  200.     Quote   = (BYTE('"'))[0]
  201.     LineNo  = 1
  202.  
  203.     WHILE NOT EOF(Unit) DO BEGIN
  204.         READF, Unit, Line
  205.         ;   Ignore blank lines and comments
  206.         IF Line NE '' AND STRMID(Line,0,1) NE '#' THEN BEGIN
  207.             ;   Complain about lines which we can't parse
  208.             MenuExt = WHERE(BYTE(Line) EQ Quote, Count)
  209.             IF Count NE 2 THEN BEGIN
  210.                 Print, "Error in definition file on line", LineNo
  211.                 GOTO, Error
  212.             ENDIF
  213.             Menu    = STRMID(Line, MenuExt[0]+1, MenuExt[1]-MenuExt[0]-1)
  214.             Class   = STRTRIM(STRMID(Line, MenuExt[1]+1, 1000), 2)
  215.             AddList = [ AddList, { WE_ADDLIST, Menu, Class } ]
  216.         ENDIF
  217.     Error:
  218.         LineNo  = LineNo + 1
  219.     ENDWHILE
  220.  
  221.     FREE_LUN, Unit
  222.  
  223.     ;   Crash and burn if addlist is empty
  224.     IF N_ELEMENTS(AddList) EQ 1 THEN BEGIN
  225.         MESSAGE, "No classes defined!. Cannot continue."
  226.     ENDIF
  227.     Addlist     = AddList[1:*]
  228.  
  229.     ;   Load class libraries
  230.  
  231.     FOR I=0,N_ELEMENTS(AddList)-1 DO BEGIN
  232.         ClearVar, Child
  233.         CALL_PROCEDURE, AddList[I].Class + "_Alloc", 0L, Child
  234.         CALL_PROCEDURE, AddList[I].Class + "_Destroy", Child
  235.     ENDFOR
  236.  
  237.     IF NOT KEYWORD_SET(NoRealize) THEN BEGIN
  238.         ;   Create primary dialog.
  239.         MAIN_Build, TopPtr, TopDlg
  240.         WIDGET_CONTROL, TopPtr, GROUP=TopDlg
  241.     ENDIF
  242.  
  243.     LastId          = 2 ; Reset
  244.  
  245.  
  246.     ;   Check for small screen size.
  247.     ;   We consider any screen less than 768 pixels tall to be a
  248.     ;   small screen
  249. ;
  250. ;   Got rid of this hack since the Mac now makes large bases scroll
  251. ;   automatically. Besides, this code didn't even work right on the Mac.
  252. ;
  253.     DEVICE, GET_SCREEN=ScreenSize
  254. ;    IF ScreenSize(1) LT 768 THEN BEGIN
  255. ;        SmallScreen     = FIX(ScreenSize * 0.75)
  256. ;        SmallScreen(0)  = SmallScreen(0) < 500  ; Hack
  257. ;    ENDIF ELSE BEGIN
  258.         SmallScreen = [0,0]
  259. ;    ENDELSE
  260.  
  261.     ;   Set XPRINTF buffer to nil
  262.     ;   Setup Xprintf ArgList (c.f. InternalXprintf in widfile.pro)
  263.  
  264.     OutputBuffer    = ""
  265.     ArgList         = STRARR(8)
  266.     ArgList[0]      = ""
  267.     ArgList[1]      = "a1"
  268.     ArgList[2]      = "a1,a2"
  269.     ArgList[3]      = "a1,a2,a3"
  270.     ArgList[4]      = "a1,a2,a3,a4"
  271.     ArgList[5]      = "a1,a2,a3,a4,a5"
  272.     ArgList[6]      = "a1,a2,a3,a4,a5,a6"
  273.     ArgList[7]      = "a1,a2,a3,a4,a5,a6,a7"
  274.  
  275. END
  276.  
  277.  
  278. ;
  279. ;  Gen_Event
  280. ;   Generic event handler.  Absorbs events the user has created by
  281. ;   playing with the
  282. ;
  283. PRO Gen_event, Event
  284.  
  285. ;   Preview event
  286.  
  287. END
  288.  
  289. ;
  290. ;  GenBase_Event
  291. ;   A event routine to absorb events handle TLB resize events of
  292. ;   preview of the user's GUI. Set XY size/offset/scrollsize in dialogs
  293. ;   to reflect change
  294. ;
  295. ;PRO GenBase_event, Event
  296. ;
  297. ;   WIDGET_CONTROL, Event.Top, GET_UVALUE=Ptr
  298. ;   Ptr2Obj, Ptr, Obj
  299. ;
  300. ;   WIDGET_CONTROL, Event.Id, TLB_GET_OFFSET=Off, TLB_GET_SIZE=Sz
  301. ;   Obj.XOffset = Off(0)
  302. ;   Obj.YOffset = Off(1)
  303. ;
  304. ;   IF Obj.XScrollSize NE 0 OR Obj.YScrollSize NE 0 THEN BEGIN
  305. ;       Obj.XScrollSize = Sz(0)
  306. ;       Obj.YScrollSize = Sz(1)
  307. ;   ENDIF ELSE BEGIN
  308. ;       Obj.XSize   = Sz(0)
  309. ;       Obj.YSize   = Sz(1)
  310. ;   ENDELSE
  311. ;
  312. ;   IF Obj.Dialog NE 0L THEN BEGIN
  313. ;       FociOff = 5 + (Obj.Type EQ "DEP")
  314. ;       WIDGET_CONTROL, Obj.Dialog, GET_UVALUE=Binfo, /NO_COPY
  315. ;
  316. ;       WIDGET_CONTROL, Binfo.Foci(FociOff), SET_VALUE=Obj.XScrollSize
  317. ;       WIDGET_CONTROL, Binfo.Foci(FociOff+1), SET_VALUE=Obj.YScrollSize
  318. ;
  319. ;       WIDGET_CONTROL, Obj.Dialog, SET_UVALUE=Binfo, /NO_COPY
  320. ;   ENDIF
  321. ;   IF Obj.AttrDlg NE 0L THEN BEGIN
  322. ;       FociOff = 5
  323. ;       WIDGET_CONTROL, Obj.AttrDlg, GET_UVALUE=Binfo, /NO_COPY
  324. ;
  325. ;       WIDGET_CONTROL, Binfo.Foci(FociOff), SET_VALUE=Obj.XSize
  326. ;       WIDGET_CONTROL, Binfo.Foci(FociOff+1), SET_VALUE=Obj.XOffset
  327. ;       WIDGET_CONTROL, Binfo.Foci(FociOff+2), SET_VALUE=Obj.YSize
  328. ;       WIDGET_CONTROL, Binfo.Foci(FociOff+3), SET_VALUE=Obj.YOffset
  329. ;
  330. ;       WIDGET_CONTROL, Obj.AttrDlg, SET_UVALUE=Binfo, /NO_COPY
  331. ;   ENDIF
  332. ;   Obj2Ptr, Obj, PTr
  333. ;END
  334.  
  335.  
  336. ;
  337. ;  Generate
  338. ;   Recreate preview to reflect current object tree information
  339. ;
  340. PRO Generate
  341.  
  342.   COMMON WidEd_Comm
  343.  
  344.     ;   Remove old preview bases
  345.  
  346.     FOR I=0,N_ELEMENTS(Bases)-1 DO BEGIN
  347.         B   = Bases[I]
  348.         IF B NE 0 AND WIDGET_INFO(B,/VALID_ID) THEN BEGIN
  349.             WIDGET_CONTROL, B, TLB_GET_OFFSET=Off
  350.             BaseXY[*,I] = Off
  351.             WIDGET_CONTROL, B, /DESTROY
  352.         ENDIF ELSE BEGIN
  353.             BaseXY[*,I] = 0
  354.         ENDELSE
  355.         Bases[I]    = 0
  356.     ENDFOR
  357.  
  358.     ;   Generate new top level bases and save their Id's
  359.     Ptr = TopPtr
  360.     I   = 0
  361.     WHILE Ptr NE 0 DO BEGIN
  362.         DEP_Generate, Ptr, NewBase, I
  363.         Bases[I]    = NewBase
  364.         I           = I + 1
  365.         Ptr         = NextPtr(Ptr)
  366.     ENDWHILE
  367. END
  368.  
  369.  
  370. ;
  371. ;  WidEd
  372. ;   Run the widget builder
  373. ;
  374. PRO WidEd, File
  375.  
  376.   COMMON WidEd_Comm
  377.  
  378.     ; Can only have one widget builder running at a time
  379.     IF XRegistered("Widget_Builder") THEN RETURN
  380.  
  381.     Init            ; Set up globals.  Build top dialog box
  382.     Generate        ; Show preview of emptywidget tree.
  383.     XManager, 'Widget_Builder', TopDlg, $
  384.         EVENT_HANDLER="MAIN_BarEvent", /JUST_REG
  385.  
  386.     ;  If user has a file in mind, open it.
  387.  
  388.     IF N_ELEMENTS(File) NE 0 THEN BEGIN
  389.         InsureExt, File, '.wid'
  390.         InternalFileOpen, File
  391.     ENDIF
  392.     XManager
  393. END
  394.